/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package caro.app.threadmanagement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author NQ
 */
public class ThreadManagement {
    private List<Thread> threads;
    public ThreadManagement(){
        threads = new ArrayList<Thread>();
    }
    public void stopThread(String name){
        Iterator<Thread> iter = threads.iterator();
        while(iter.hasNext()){
            Thread thread = iter.next();
            if(thread.getName().equals(name)){
                if(thread.isAlive())
                    thread.stop();
            }
        }
    }
    public void startThread(String name){
        Iterator<Thread> iter = threads.iterator();
        while(iter.hasNext()){
            Thread thread = iter.next();
            if(thread.getName().equals(name)){
                if(!thread.isAlive())
                    thread.start();
            }
        }
    }
    public void addThread(Thread a){
        threads.add(a);
        a.start();
    }
    public void removeThread(Thread a){
        
        threads.remove(a);
        if(a.isAlive())
            a.stop();
    }
}
